﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace NetfractionHub.Network.Protocol.BASE
{
    [ProtocolFeature(Name="BASE")]
    public class ProtocolFeatureBASE : ProtocolFeature
    {
        public struct FeatureActions
        {
            [ProtocolFeatureAction(ActionType = FeatureActionType.Message)]
            public const string ActionSTA = "STA";
            [ProtocolFeatureAction(ActionType = FeatureActionType.Message)]
            public const string ActionSUP = "SUP";
            [ProtocolFeatureAction(ActionType = FeatureActionType.Message)]
            public const string ActionSID = "SID";
            [ProtocolFeatureAction(ActionType = FeatureActionType.Message)]
            public const string ActionINF = "INF";
            [ProtocolFeatureAction(ActionType = FeatureActionType.Message)]
            public const string ActionMSG = "MSG";
            [ProtocolFeatureAction(ActionType = FeatureActionType.Message)]
            public const string ActionSCH = "SCH";
            [ProtocolFeatureAction(ActionType = FeatureActionType.Message)]
            public const string ActionRES = "RES";
            [ProtocolFeatureAction(ActionType = FeatureActionType.Message)]
            public const string ActionCTM = "CTM";
            [ProtocolFeatureAction(ActionType = FeatureActionType.Message)]
            public const string ActionRCM = "RCM";
            [ProtocolFeatureAction(ActionType = FeatureActionType.Message)]
            public const string ActionGPA = "GPA";
            [ProtocolFeatureAction(ActionType = FeatureActionType.Message)]
            public const string ActionPAS = "PAS";
            [ProtocolFeatureAction(ActionType = FeatureActionType.Message)]
            public const string ActionQUI = "QUI";
            /*
             * These messsages are not valid when sent between the hub and client.
            [ProtocolFeatureAction(ActionType = FeatureActionType.Message)]
            public const string ActionGET = "GET";
            [ProtocolFeatureAction(ActionType = FeatureActionType.Message)]
            public const string ActionGFI = "GFI";
            [ProtocolFeatureAction(ActionType = FeatureActionType.Message)]
            public const string ActionSND = "SND";*/
        }

        public ProtocolFeatureBASE()
        {
            this.SupportedActions.AddRange(base.GetFeatureActions(new FeatureActions()));
            
            // Register Handlers
            this.ProtocolMessageHandlers.Add(new ProtocolFeatureAction(FeatureActions.ActionSUP, FeatureActionType.Message), new Handler.HandlerSUP());
            this.ProtocolMessageHandlers.Add(new ProtocolFeatureAction(FeatureActions.ActionINF, FeatureActionType.Message), new Handler.HandlerINF());
            this.ProtocolMessageHandlers.Add(new ProtocolFeatureAction(FeatureActions.ActionMSG, FeatureActionType.Message), new Handler.HandlerMSG());
            this.ProtocolMessageHandlers.Add(new ProtocolFeatureAction(FeatureActions.ActionCTM, FeatureActionType.Message), new Handler.HandlerCTM());
            this.ProtocolMessageHandlers.Add(new ProtocolFeatureAction(FeatureActions.ActionRCM, FeatureActionType.Message), new Handler.HandlerRCM());
            this.ProtocolMessageHandlers.Add(new ProtocolFeatureAction(FeatureActions.ActionRES, FeatureActionType.Message), new Handler.HandlerRES());
            this.ProtocolMessageHandlers.Add(new ProtocolFeatureAction(FeatureActions.ActionSCH, FeatureActionType.Message), new Handler.HandlerSCH());
            this.ProtocolMessageHandlers.Add(new ProtocolFeatureAction(FeatureActions.ActionPAS, FeatureActionType.Message), new Handler.HandlerPAS());
        }

        /// <summary>
        /// Overrides the ProtocolFeature.HandleConnect method
        /// </summary>        
        public override bool HandleConnect(RemoteMachine.Node node)
        {
            return true;
        }

        /// <summary>
        /// Overrides the ProtocolFeature.HandleDisconnect method
        /// </summary>        
        public override bool HandleDisconnect(RemoteMachine.Node node)
        {
            return true;
        }
    }
}
